import SocketServer

class ClientHandler(SocketServer.BaseRequestHandler):
   def __init__(self, request, client_address, server):
      super(ClientHandler, self).__init__(request, client_address, server)
      self._bgpMaxPacketSize = 4096
      self._bgpMinPacketSize = 19

   def setup(self):
      super(ClientHandler, self).setup()

   def handle(self):
      data = self.request.recv(self._bgpMaxPacketSize)
      if data > self._bgpMaxPacketSize or data < self._bgpMinPacketSize:
         print("Invalid BGP packet size!")

      self.request.send(data)
      
   def finish(self):
      super(ClientHandler, self).finish()

class BgpServer(SocketServer.TCPServer):
   def __init__(self, server_address, handler_class = ClientHandler)
      super(BgpServer, self).__init__(server_address, handler_class)
      self._runflag = True

   def server_activate(self):
      super(BgpServer, self).server_activate()

   def serve_forever(self):
      while self._runflag:
         self.handle_request()

   def handle_request(self):
      super(BgpServer, self).handle_request()

   def verify_request(self, request, client_address):
      super(BgpServer, self).verify_request(request, client_address)

   def server_close(self):
      super(BgpServer, self).server_close()
